export type ActionHandler<T> = (status: number, response: T, message: string) => void
export type AsyncHandler<T> = (status: number, response: T, message: string) => void

export enum ActionResultCode {
  Ok = 0,
  Error = -1
}

export const COMMON_ERROR_MESSAGE = "操作失败";

export class ActionResult<T> {
  code: ActionResultCode
  response?: T
  message?: string

  constructor(code: ActionResultCode, res: T, msg: string) {
    this.code = code;
    this.response = res;
    this.message = msg;
  }

  isOk(): boolean {
    return this.code == ActionResultCode.Ok;
  }

  static res<T>(res: T): ActionResult<T> {
    return new ActionResult(ActionResultCode.Ok, res, "");
  }


  static ok(): ActionResult<undefined> {
    return new ActionResult(ActionResultCode.Ok, undefined, "");
  }
}
